<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Machine as MachineM;
use think\Db;

/**
 * 矿机接口
 */
class Machine extends Api
{
    /**
     * 矿机列表
     */
    public function machine_list()
    {
        $list = MachineM::machine_list();
        $this->success('返回成功', $list);
    }

    /**
     * 购买矿机
    */
    public function buy_machine()
    {
        if ($this->request->isPost()) {
            $params = request()->post();
            if ($params['id'] > 0) {
                $result = MachineM::buy_machine($params['id'], $this->auth->id);
                if ($result['error'] > 0) {
                    $this->error($result['msg'], [], $result['error']);
                } else {
                    $this->success('购买成功');
                }
            } else {
                $this->error('矿机ID错误');
            }
        } else {
            $this->error('请求错误');
        }
    }
}
